#ifndef __ENCODER_H
#define __ENCODER_H

#include "main.h"
#include "tim.h"
#include "motor/motor.h"
#include "pid/pid.h"
#include "niming/niming.h"

// 编码器的计数值
extern volatile short Encoder1_Count;
extern volatile short Encoder2_Count;

// 开启定时器的编码器
#define ENCODERA_START() HAL_TIM_Encoder_Start(&htim3,TIM_CHANNEL_ALL)
#define ENCODERB_START() HAL_TIM_Encoder_Start(&htim4,TIM_CHANNEL_ALL)

// 开启定时器的编码器中断
#define ENCODERA_IRQ_START() HAL_TIM_Base_Start_IT(&htim3)
#define ENCODERB_IRQ_START() HAL_TIM_Base_Start_IT(&htim4)

// 获取定时器的编码器计数值
#define ENCODERA_GET_COUNTER() (short)__HAL_TIM_GET_COUNTER(&htim3)
#define ENCODERB_GET_COUNTER() (short)__HAL_TIM_GET_COUNTER(&htim4)

// 设置定时器的编码器计数值
#define ENCODERA_SET_COUNTER(x) __HAL_TIM_SET_COUNTER(&htim3,x)
#define ENCODERB_SET_COUNTER(x) __HAL_TIM_SET_COUNTER(&htim4,x)

// 设置定时器的编码器计数值为零
#define ENCODERA_SET_COUNTER_ZERO() ENCODERA_SET_COUNTER(0)
#define ENCODERB_SET_COUNTER_ZERO() ENCODERB_SET_COUNTER(0)

// 开启定时器读取定时器的编码器计数值
#define ENCODER_READ_COUNTER_IRQ_START() HAL_TIM_Base_Start_IT(&htim2)

#endif
